Skip to content

fix: Sanitize index names to support CouchDB > 3.3.3#1668

Open
Crash-- wants to merge 1 commit intomasterfrom
fix/sanitize-index-name
Open

fix: Sanitize index names to support CouchDB > 3.3.3#1668
Crash-- wants to merge 1 commit intomasterfrom
fix/sanitize-index-name

Conversation

@Crash--
Copy link
Copy Markdown
Contributor

@Crash-- Crash-- commented Feb 12, 2026

I didn't find a commit from CouchDB relative to this issue, but it's somewhere between 3.3.3 & 3.5.1.

Partial filter values containing "/" (e.g. "/Settings") produced index names incompatible with new CouchDB. Percent-encode "/" as "%2F" (and "%" as "%25") to avoid naming issues while preserving uniqueness.

Closes #1667

Summary by CodeRabbit

  • Bug Fixes

    • Index name generation now encodes special characters (forward slashes and percent signs) for filtered queries, preventing invalid names and ensuring consistent query behavior.
  • Tests

    • Added tests verifying proper encoding of special characters in index names and that distinct indexes are produced when filter values differ.

@Crash-- Crash-- requested a review from paultranvan as a code owner February 12, 2026 07:56
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 12, 2026

Walkthrough

The change adds a private helper sanitizeIndexName in two packages (cozy-pouch-link and cozy-stack-client) that percent-encodes % as %25 and / as %2F. getIndexNameFromFields is updated in both packages to apply this sanitization when a partialFilter is present. Tests were added to verify slash encoding and that index names differ when partial filter values contain a slash. No public API signatures were changed.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: sanitizing index names to support newer CouchDB versions, directly addressing the core fix in the PR.
Linked Issues check ✅ Passed The PR fully satisfies issue #1667 by implementing percent-encoding of '/' as '%2F' and '%' as '%25' in index names, with test coverage validating the sanitization behavior.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing and testing index name sanitization; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/sanitize-index-name

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Crash-- Crash-- requested a review from zatteo February 12, 2026 07:56
I didn't find a commit from CouchDB relative to this issue,
but it's somewhere between 3.3.3 & 3.5.1.

Partial filter values containing "/" (e.g. "/Settings") produced index
names incompatible with new CouchDB. Percent-encode "/" as "%2F" (and
"%" as "%25") to avoid naming issues while preserving uniqueness.

Closes #1667
@Crash-- Crash-- force-pushed the fix/sanitize-index-name branch from c1e54f3 to 486a2ef Compare February 12, 2026 07:59
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/cozy-stack-client/src/mangoIndex.spec.js`:
- Around line 258-274: The test's partialFilter defines a $nin array spread
across multiple lines which trips Prettier; update the test "should sanitize
slash characters from index name" so the $nin arrays (both for _id and for
path.$or[1].$nin) are formatted on a single line (e.g. ['$a','/Settings'] style)
to satisfy Prettier, keeping the same values and leaving the rest of the test
and the call to getIndexNameFromFields unchanged.
🧹 Nitpick comments (1)
packages/cozy-stack-client/src/mangoIndex.js (1)

108-118: Consider extracting sanitizeIndexName to a shared utility.

This function is duplicated verbatim in packages/cozy-pouch-link/src/mango.js. While the existing "Warning" comments remind developers to keep them in sync, a shared module would eliminate the risk of divergence. Low priority given the existing convention in this codebase.

Comment thread packages/cozy-stack-client/src/mangoIndex.spec.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Index sanitization

2 participants